package com.kitten.search.biz.controller;

import com.kitten.framework.biz.operationlog.annotation.ApiOperationLog;
import com.kitten.framework.common.response.Response;
import com.kitten.search.api.dto.RebuildNoteDocumentReqDTO;
import com.kitten.search.api.dto.RebuildUserDocumentReqDTO;
import com.kitten.search.biz.model.vo.SearchNoteReqVO;
import com.kitten.search.biz.model.vo.SearchUserReqVO;
import com.kitten.search.biz.service.ExtDictService;
import com.kitten.search.biz.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author kitten
 */
@Slf4j
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;
    @Autowired
    private ExtDictService extDictService;

    @ApiOperationLog(description = "搜索用户")
    @PostMapping("/user")
    public Response searchUser(@RequestBody @Validated SearchUserReqVO searchUserReqVO) {
        return searchService.searchUser(searchUserReqVO);
    }

    @ApiOperationLog(description = "搜索笔记")
    @PostMapping("/note")
    public Response searchNote(@RequestBody @Validated SearchNoteReqVO searchNoteReqVO) {
        return searchService.searchNote(searchNoteReqVO);
    }

    @ApiOperationLog(description = "获取热更新字典")
    @GetMapping("/ext/dict")
    public ResponseEntity<String> extDict() {
        return extDictService.getHotUpdateExtDict();
    }


    // ==================================API=================================
    @ApiOperationLog(description = "重建笔记文档")
    @PostMapping("/note/rebuild")
    public Response<Long> rebuildNoteDocument(@RequestBody @Validated RebuildNoteDocumentReqDTO rebuildNoteDocumentReqDTO) {
        return searchService.rebuildNoteDocument(rebuildNoteDocumentReqDTO);
    }

    @ApiOperationLog(description = "重建用户文档")
    @PostMapping("/user/rebuild")
    public Response<Long> rebuildUserDocument(@RequestBody @Validated RebuildUserDocumentReqDTO rebuildUserDocumentReqDTO) {
        return searchService.rebuildUserDocument(rebuildUserDocumentReqDTO);
    }

}
